package com.kangye.exam.service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.exam.bean.Teacher;
import com.kangye.exam.dao.TeacherDao;
import com.kangye.exam.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "teacherService")
public class TeacherServiceImpl implements TeacherService {

   @Resource
   private TeacherDao teacherDao;

    @Override
    public Teacher getTeaLogin(String teacherUser, String teacherPass) {
        Map map = new HashMap();
        map.put("teacherUser",teacherUser);
        map.put("teacherPass",teacherPass);
        Teacher teacher = teacherDao.getTeaLogin(map);
        return teacher;
    }

    @Override
    public Teacher queryTeaId(int teacherId) {
        return teacherDao.queryTeaId(teacherId);
    }

    @Override
    public PageInfo<Teacher> queryTAll(Integer pageNum, Integer pageSize) {
       //分页查询 , pageNum 当前页 pageSize 每页n条数据
        PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teachers = teacherDao.queryTAll();
        //查询结果存放info中
        PageInfo<Teacher> info = new PageInfo<>(teachers);
        return info;
    }

    @Override
    public PageInfo<Teacher> teacherList(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Map map = new HashMap();
        map.put("name",name);
        List<Teacher> teachers = teacherDao.teacherList(map);
        PageInfo<Teacher> info = new PageInfo<>(teachers);
        return info;
    }

    @Override
    public void insertTea(Teacher teacher) {
        teacherDao.insertTea(teacher);
    }

    @Override
    public void updateTea(Teacher teacher) {
        teacherDao.updateTea(teacher);
    }

    @Override
    public void deleteTId(int teacherId) {
        teacherDao.deleteTId(teacherId);
    }
}
